package com.whcoding.test.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Date;


/**
 * @author Manager
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
//链式写法
@Accessors(chain = true)
@EqualsAndHashCode
public class OrmDeptVO implements Serializable {
	private Long id;
	private Integer deptId;
	private String deptNo;
	private Integer deptType;
	private String deptName;
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date createTime;
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
	private Date updateTime;
	private transient BigDecimal deptPerf;
	private Integer isValidFlag;
	private String shortName;
	private String remark;


	@Override
	public String toString() {
		return modelToString(this);
	}

	/**
	 * 重写ToString
	 *
	 * @param t
	 * @param <T>
	 * @return
	 */
	public static <T> String modelToString(T t) {
		StringBuilder result = new StringBuilder("[");

		for (Field declaredField : t.getClass().getDeclaredFields()) {
			try {
				result
						.append(declaredField.getName())
						.append("=")
						.append(declaredField.get(t))
						.append(",");
			} catch (IllegalAccessException e) {
				declaredField.setAccessible(true);
				try {
					result
							.append(declaredField.get(t))
							.append(",");
				} catch (IllegalAccessException e1) {
					e1.printStackTrace();
				}
				declaredField.setAccessible(false);
			}
		}
		return result.substring(0, result.length() - 1) + "]";
	}
}
